<template>
	<el-dialog :title="titleMap[mode]" v-model="visible" customClass="customWidth" destroy-on-close @closed="$emit('closed')">
		<el-form :model="form" :rules="rules" ref="dialogForm" label-width="100px" label-position="left">
			<el-row :gutter="24">
				<el-col :lg="12">
					<el-form-item label="供应商等级" prop="level">
						<sc-select v-model="form.level" :params="{code:'entLevel'}" :apiObj="$API.invite.inviteDic.getInviteDicByCode" clearable filterable style="width: 100%"></sc-select>
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="排序号" prop="sortNo">
						<el-input-number v-model="form.sortNo" clearable min="0"></el-input-number>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row :gutter="24">
				<el-col :lg="12">
					<el-form-item label="企业名称" prop="name">
						<el-input v-model="form.name" clearable maxlength="50" placeholder="企业名称" ></el-input>
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="企业编号" prop="codeNo">
						<el-input v-model="form.codeNo" clearable maxlength="50" placeholder="企业编号" ></el-input>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row :gutter="24">
				<el-col :lg="12">
					<el-form-item label="企业法人" prop="legalPerson">
						<el-input v-model="form.legalPerson" clearable maxlength="50" placeholder="企业法人" ></el-input>
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="信用代码" prop="creditCode">
						<el-input v-model="form.creditCode" clearable maxlength="18" placeholder="统一信用代码" ></el-input>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row :gutter="24">
				<el-col :lg="12">
					<el-form-item label="企业类型" prop="entType">
						<sc-select v-model="form.entType" :params="{code:'entType'}" :apiObj="$API.invite.inviteDic.getInviteDicByCode" clearable filterable style="width: 100%"></sc-select>
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="企业规模" prop="enterpriseSize">
						<sc-select v-model="form.enterpriseSize" :params="{code:'enterpriseSize'}" :apiObj="$API.invite.inviteDic.getInviteDicByCode" clearable filterable style="width: 100%"></sc-select>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row :gutter="24">
				<el-col :lg="12">
					<el-form-item label="注册资本" prop="registeredCapital">
						<el-input v-model="form.registeredCapital" placeholder="注册资本" clearable>
							<template #append>万元</template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="注册日期" prop="registrationDate">
						<el-date-picker v-model="form.registrationDate" placeholder="注册日期" type="date" value-format="YYYY-MM-DD" style="width: 100%;"></el-date-picker>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row :gutter="24">
				<el-col :lg="12">
					<el-form-item label="注册地址" prop="registeredAddress">
						<el-input v-model="form.registeredAddress" placeholder="注册地址" clearable maxlength="80"></el-input>
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="信用等级" prop="creditRating">
						<sc-select v-model="form.creditRating" :params="{code:'creditRating'}" :apiObj="$API.invite.inviteDic.getInviteDicByCode" clearable filterable style="width: 100%"></sc-select>
					</el-form-item>
				</el-col>
			</el-row>
			<el-form-item label="经营范围" prop="businessScope">
				<el-input v-model="form.businessScope" placeholder="经营范围" clearable  type="textarea"></el-input>
			</el-form-item>
			<el-divider>联系人</el-divider>
			<el-row :gutter="24">
				<el-col :lg="12">
					<el-form-item label="联系人" prop="linkMan">
						<el-input v-model="form.linkMan" placeholder="联系人" clearable maxlength="50"></el-input>
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="系统电话" prop="linkTel">
						<el-input v-model="form.linkTel" placeholder="系统电话" clearable maxlength="20"></el-input>
					</el-form-item>
				</el-col>
			</el-row>

			<el-row :gutter="24">
				<el-col :lg="12">
					<el-form-item label="电子邮件" prop="email">
						<el-input v-model="form.email" placeholder="电子邮件" clearable maxlength="50"></el-input>
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="联系地址" prop="address">
						<el-input v-model="form.address" placeholder="联系地址" clearable maxlength="20"></el-input>
					</el-form-item>
				</el-col>
			</el-row>
			<el-form-item label="备注说明" prop="remark">
				<el-input v-model="form.remark" placeholder="备注说明" clearable maxlength="380" type="textarea"></el-input>
			</el-form-item>
		</el-form>
		<template #footer>
			<el-button @click="visible=false">取 消</el-button>
			<el-button v-if="mode!='show'" type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
		</template>
	</el-dialog>

</template>
<script>
export default {
	emits: ['success', 'closed'],
	components: {
	},
	data() {
		return {
			visible: false,
			isSaveing: false,
			mode: "add",
			titleMap: {
				add: '创建供应商',
				edit: '编辑供应商',
			},
			templates: [],
			form: {
				entId:'',
				name: '',
				sortNo:0,
				codeNo: "",
				creditCode: '',
				legalPerson: '',
				businessScope: '',
				enterpriseSize: '',
				registeredCapital:0.0,
				registrationDate:'',
				registeredAddress:'',
				creditRating:'',
				address:'',
				linkTel:'',
				linkMan:'',
				email:'',
				entType:'',
				level:'',
				status:'0',
				remark:''
			},
			rules: {
				name: [
					{required: true, message: '企业名称不能为空', trigger: 'blur'}
				],
				codeNo: [
					{required: true, message: '企业编号不能为空', trigger: 'blur'}
				],
				legalPerson: [
					{required: true, message: '企业法人不能为空', trigger: 'blur'}
				],
				creditCode: [
					{required: true, message: '信用代码不能为空', trigger: 'blur'}
				]
			}
		}
	},
	mounted() {
	},
	methods: {
		//显示
		open(mode = 'add') {
			this.mode = mode;
			this.visible = true;
			return this
		},
		submit() {
			this.$refs.dialogForm.validate(async (valid) => {
				if (valid) {
					this.isSaveing = true;
					var res;
					if (this.mode == "add") {
						res = await this.$API.invite.inviteEnt.insertInviteEnt.post(this.form);
					} else if (this.mode == "edit") {
						res = await this.$API.invite.inviteEnt.updateInviteEnt.post(this.form);
					}
					this.isSaveing = false;
					if (res.code == 200) {
						this.$emit('success')
						this.visible = false;
						this.$message.success("操作成功")
					} else {
						this.$alert(res.message, "提示", {type: 'error'})
					}
				}
			})
		},
		setData(data) {
			this.form.entId = data.entId
			this.form.name = data.name
			this.form.sortNo = data.sortNo
			this.form.codeNo = data.codeNo
			this.form.creditCode = data.creditCode
			this.form.legalPerson = data.legalPerson
			this.form.businessScope = data.businessScope
			this.form.enterpriseSize = data.enterpriseSize
			this.form.registeredCapital = data.registeredCapital
			this.form.registrationDate = data.registrationDate
			this.form.registeredAddress = data.registeredAddress
			this.form.creditRating = data.creditRating
			this.form.address = data.address
			this.form.linkTel = data.linkTel
			this.form.linkMan = data.linkMan
			this.form.email = data.email
			this.form.entType = data.entType
			this.form.level = data.level
			this.form.status = data.status
			this.form.remark = data.remark
		},
	}
}
</script>

<style>
.customWidth {
	width: 60%;
}
</style>
